package com.sky.mapper;
import com.github.pagehelper.Page;
import com.sky.annotation.Autofill;
import com.sky.dto.SetmealPageQueryDTO;
import com.sky.entity.Setmeal;
import com.sky.enumeration.OperationType;
import com.sky.vo.DishItemVO;
import com.sky.vo.SetmealVO;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Options;
import org.apache.ibatis.annotations.Select;
import java.util.List;
import java.util.Map;

/**
 * @Description TODO
 * @Author itheima
 * @Date 2023-07-09 15:52
 */
@Mapper
public interface SetmealMapper {
    /**
     * 根据关联Id查询
     * @param CategoryId
     * @return
     */
    @Select("select count(id) from setmeal where Category_id=#{CategoryId}")
    Integer countByCategoryId( long CategoryId);

    /**
     * 增加套餐
     * @param setmeal
     */
    @Insert("insert into  setmeal (category_id, name, price, description, image, create_time, update_time, create_user, update_user) \n" +
            "VALUES(#{categoryId},#{name},#{price},#{description},#{image},#{createTime},#{updateTime},#{createUser},#{updateUser})  ")
    @Autofill
    @Options(useGeneratedKeys = true,keyProperty = "id")
   void addsetmeal(Setmeal setmeal);

    /**
     * 分页查询
     * @param setmealPageQueryDTO
     * @return
     */
    Page<SetmealVO> pageSetmea(SetmealPageQueryDTO setmealPageQueryDTO);

    /**
     * 修改套餐
     * @param setmeal
     */
    @Autofill(OperationType.UPDATE)
    void update(Setmeal setmeal);

    /**
     * 根据id查询
     *
     * @param id
     * @return
     */
    @Select("select * from setmeal where id = #{id}")
    Setmeal getById(Long id);

    /**
     * 根据id集合查询出在出售状态套餐的个数
     * @param ids
     * @return
     */
    Integer getbyids(List<Long> ids);

    /**
     * 批量删除
     * @param ids
     */
    void deleteids(List<Long> ids);
    /**
     * 动态条件查询套餐
     * @param setmeal
     * @return
     */
    List<Setmeal> list(Setmeal setmeal);

    /**
     * 根据套餐id查询菜品选项
     * @param setmealId
     * @return
     */
    @Select("select sd.name, sd.copies, d.image, d.description " +
            "from setmeal_dish sd left join dish d on sd.dish_id = d.id " +
            "where sd.setmeal_id = #{setmealId}")
    List<DishItemVO> getDishItemBySetmealId(Long setmealId);
    /**
     * 根据条件统计套餐数量
     * @param map
     * @return
     */
    Integer countByMap(Map map);
}
